<?php

namespace App\Kuafu\Shop\Controller\B;

use App\Kuafu\Base\Controller\BaseController;
use App\Kuafu\Shop\Service\ShopAttributeService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ShopAttributeController extends BaseController
{


    /**
     * 属性值列表
     * @param Request $request
     * @return JsonResponse
     */
    public function getAttributeList(Request $request): JsonResponse
    {
        return $this->success(ShopAttributeService::getAttributeList(true));
    }


    /**
     * 属性值详情
     * @param Request $request
     * @param int $id
     * @return JsonResponse
     */
    public function getAttributeInfo(Request $request, int $id): JsonResponse
    {
        return $this->success(ShopAttributeService::getAttributeInfo($id));
    }


    /**
     * 属性值编辑
     * @param Request $request
     * @param int $id
     * @return JsonResponse
     */
    public function updateAttribute(Request $request, int $id): JsonResponse
    {
        $this->validate($request, [
            'data' => 'required|array',
        ]);
        $data = $request->get('data');

        $rmsUserId = auth('api')->user()->id;
        return $this->success(ShopAttributeService::updateAttribute($id, $data, $rmsUserId));
    }
}
